<?php
namespace Api;

use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

/**
 * 会员卡券
 * Class MemberCoupon
 * @package Api
 */
class MemberCoupon extends Api
{
    private $MemberCoupon = null;
    public function __construct()
    {
        parent::__construct();
        $this->MemberCoupon = new \Controller\MemberCoupon();
    }

    /**
     * 获取用户卡券
     */
    public function getUserList()
    {
        Util::appointGet();
        $_list = $this->MemberCoupon->getUserList($this->_gpc["type"],$this->_gpc["limit"]);
        if($_list) {
            $_result = array("code"=>0,"data"=>$_list);
        } else {
            $_result = array("code"=>101);
        }
        Util::returns($_result);
    }

    /**
     * 获取卡券详情
     */
    public function get()
    {
        Util::appointGet();
        $_data = $this->MemberCoupon->get($this->_gpc["member_coupon_id"]);
        if($_data) {
            $_result = array("code"=>0,"data"=>$_data);
        } else {
            $_result = array("code"=>100);
        }
        Util::returns($_result);
    }

    /**
     * 删除用户卡券
     */
    public function del()
    {
        Util::appointPost();
        if($this->MemberCoupon->del($this->_gpc["member_coupon_id"])) {
            $_result = array("code"=>0);
        } else {
            $_result = array("code"=>102);
        }
        Util::returns($_result);
    }

    /**
     *获取核销二维码所需连接地址
     */
    public function getScanUrl()
    {
        Util::appointPost();
        $_url = murl('entry//scan',array('m'=>KUYUAN_NAME,"scan_type"=>"check_coupon","member_coupon_id"=>$this->_gpc["member_coupon_id"]),true,true);
        Util::returns(array("code"=>0,"data"=>$_url));
    }
}